﻿namespace _71_C_监听系统文件状态变化
{
    internal class Program
    {
        private static FileSystemWatcher _watcher = new FileSystemWatcher();
        static void Main(string[] args)
        {
            _watcher.Path = AppDomain.CurrentDomain.BaseDirectory;
            _watcher.IncludeSubdirectories = true;
            _watcher.Created += _watcher_Created;
            _watcher.Changed += _watcher_Changed;
            _watcher.Renamed += _watcher_Renamed;
            _watcher.Deleted += _watcher_Deleted;
            _watcher.EnableRaisingEvents = true;
            Console.ReadKey();
        }

        private static void _watcher_Deleted(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath + "...此文件被删除了");
        }

        private static void _watcher_Renamed(object sender, RenamedEventArgs e)
        {
            Console.WriteLine(e.OldName + "...文件被重命名了：为：" + e.Name);
        }

        private static void _watcher_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath+"...文件被修改了");
        }

        private static void _watcher_Created(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath+"...文件被创建");
        }
    }
}
